/*
 * GeoVISTA Center (Penn State, Dept. of Geography)
 * Copyright (c), 2003-2011,  Jin Chen and Alan M. MacEachren, GeoVISTA Center, Penn State University
 * All Rights Researved.
 *
 * This library is developed and distributed for free usage,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * You can redistribute and/or modify it under the terms of the
 * Simplified BSD License
 *
 *
 *
 *
 *
 *
 *
 * To show ChooseData Dialog
 * @Original Author: jin Chen
 * @date: Apr 15, 2004$
 * @version: 1.0
 */
package edu.psu.geovista.app.dataloader.v1.actions;

import edu.psu.geovista.app.dataloader.v1.config.model.Pcpdata;
import edu.psu.geovista.app.dataloader.v1.config.model.Project;
import edu.psu.geovista.app.dataloader.v1.gui.ChooseDataPane;
import edu.psu.geovista.app.dataloader.v1.session.ProjectBuilder;

import java.awt.event.ActionEvent;

public class ShowChooseData70 extends BasicAction{
    public void actionPerformed(ActionEvent e) {
        System.out.println(this.getClass().getName() + " processing -->");
        processInfoFromPreviousPage();
        processInforForNextPage();
        doNext();
        /*   boolean success=dataloader.setDataInfo(projectname) ;
        if(success)*/

         /*this.wizard.setLoadPcpdata(this.dataloader.getChooseDataPane().isPcpDataLoad());
         this.wizard.setLoadTsdata(this.dataloader.getChooseDataPane().isTsDataLoad());*/

       System.out.println(this.getClass().getName() + " <-- processed ");


    }

    protected  void processInfoFromPreviousPage(){
         System.out.println(this.getClass().getName() + " processInfoFromPreviousPage processing -->");
          String projectname=this.dataloader.getProjectPane().getSelectedProjectName();
        System.out.println("project name "+projectname);
        if(wizardData.getProjectCategory()== WizardData.New ){
            wizardData.clean() ;//if load a existing project and then load a new one, need to clean wizard
            wizardData.setProjectName(projectname);
            wizardData.setLoadPcpdata(true);
            wizardData.setLoadTsdata(true);
            //ProjectType currPj = wizard.getProjectClone();
            //currPj.setID(projectname);
            //currPj.getPcpdata().setLoad(true);
            //currPj.getTsdata().setLoad(true);
        }
        else{// 
             System.out.println(this.getClass().getName() + " exisiting project");
            //1. get info (project name) from previous GUI
           if(wizardData.hasProject(projectname)){
                // 
               System.out.println("has project");
            }
            else{// 
                // 2. load project's information
                ProjectBuilder projBd = dataloader.getProjBd();
               System.out.println("get projbd");
                //ConfigureProcessor config=projBd.getConfiguror();
                Project project=projBd.getProject(projectname);//0416 config.getProjectByID(projectname);
               System.out.println("get project");
                this.wizardData.setProject(project);
               System.out.println(" set project");
            }
        }

    }
    protected  void processInforForNextPage(){
        System.out.println(this.getClass().getName() + " processInforForNextPage processing -->");
        //2. fill data for the next GUI(ChooseDataPane).
        ChooseDataPane chp = this.dataloader.getChooseDataPane();
        Project currPj = wizardData.getProjectClone();
        Pcpdata pcpdata = currPj.getPcpdata();
        boolean loadpcp=pcpdata.isLoad() ;
        boolean loadts=currPj.getTsdata().isLoad() ;
        chp.setPcpDataLoad(loadpcp);
        chp.setTsDataLoad(loadts);
    }
    protected void doNext(){
        System.out.println(this.getClass().getName() + " doNext processing -->");
        dataloader.showChooseDataDlg();
    }
}
